package com.xs.room.user.controller;

import com.github.pagehelper.PageInfo;
import com.xs.room.common.entity.Result;
import com.xs.room.common.entity.ResultStatus;
import com.xs.room.user.entity.User;
import com.xs.room.user.mapper.UserMapper;
import com.xs.room.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("users")
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 根据名字(username)查找用户
     * @param username
     * @return
     */
    @GetMapping("{username}")
    public Result<User> queryUser(@PathVariable String username) {
        User user = userService.queryByUsername(username);
        return Result.of(ResultStatus.SUCCESS, user);
    }

    /**
     * 分页查询
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping
    public PageInfo<User> listUser(@RequestParam(defaultValue = "1") int pageNum,
                                   @RequestParam(defaultValue = "10") int pageSize) {

        return userService.list(pageNum, pageSize);
    }

}
